package com.qfedu.edu.config;

import com.qfedu.edu.interceptor.GlobalInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * WebMvcConfigurerAdapter：一旦继承了这个类就要重新映射静态资源
 *
 *
 * 为Mvc编写配置类
 */
@SpringBootConfiguration
public class MyMvcConfig extends WebMvcConfigurerAdapter {

    // 注入自定义拦截器
    @Autowired
    private GlobalInterceptor globalInterceptor;

    /**
     * 添加拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 将自定义拦截器添加到拦截器中
        registry.addInterceptor(globalInterceptor);
    }
    // 映射静态资源
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 映射静态资源
        registry.addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/");
    }
}
